﻿using Microsoft.AspNetCore.Mvc;
using WebAPI.Utility;

namespace WebAPI.Controllers
{
    [ApiController]
    [Route("v2/[controller]/[action]")]
    [ApiExplorerSettings(GroupName = nameof(ApiVersionInfo.V2))] 
    public class FirstV2Controller : ControllerBase
    {
        private readonly ILogger<FirstV2Controller> _logger;

        public FirstV2Controller(ILogger<FirstV2Controller> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        //[Route("GetData")] 
        //[CustomCorsActionFilterAttribute]
        public object GetData()
        {
            //HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*"); 
            Console.WriteLine("FirstV2Controller-GetData-请求到了~~");
            return new
            {
                Id = 123,
                Name = "Richard"
            };
        }

        /// <summary>
        /// 提交数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        //[Route("PostData")]
        public object PostData()
        {
            return new
            {
                Success = true,
                Mesaage = "OK"
            };
        }

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        //[Route("PutData")]
        public object PutData()
        {
            return new
            {
                Success = true,
                Mesaage = "OK"
            };
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <returns></returns>
        [HttpDelete]
        //[Route("DeleteData")]
        public object DeleteData()
        {
            return new
            {
                Success = true,
                Mesaage = "OK"
            };
        }
    }
}
